blktap: Fix compile errors
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 24 May 2007 13:07:40 +0000 (14:07 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 24 May 2007 13:07:40 +0000 (14:07 +0100)
When compiling the various blktap drivers with warnings cranked up, I
get errors that return values are not checked.

Signed-off-by: Charles Coffing <ccoffing@novell.com>
tools/blktap/drivers/blktapctrl.c
tools/blktap/drivers/block-qcow.c
tools/blktap/drivers/block-vmdk.c

index a0b2f349d0753197d33ecbe61a7ec22056401d66..aeec870af29ba20a559e3132fc34158e2b956933 100644 (file)
@@ -678,7 +678,10 @@ int main(int argc, char *argv[])
        __init_blkif();
        snprintf(buf, sizeof(buf), "BLKTAPCTRL[%d]", getpid());
        openlog(buf, LOG_CONS|LOG_ODELAY, LOG_DAEMON);
-       daemon(0,0);
+       if (daemon(0,0)) {
+               DPRINTF("daemon failed (%d)\n", errno);
+               goto open_failed;
+       }
 
        print_drivers();
        init_driver_list();
index 5eaf1417581aac38f609e7a401edb39a9ffaf6b5..a1fab17c55ee4f471d127e4ee20621a5524ce557 100644 (file)
@@ -745,7 +745,10 @@ found:
                }
                memcpy(tmp_ptr2, l2_ptr, 4096);
                lseek(s->fd, l2_offset + (l2_sector << 12), SEEK_SET);
-               write(s->fd, tmp_ptr2, 4096);
+               if (write(s->fd, tmp_ptr2, 4096) != 4096) {
+                       free(tmp_ptr2);
+                       return -1;
+               }
                free(tmp_ptr2);
        }
        return cluster_offset;
@@ -1252,8 +1255,8 @@ int qcow_create(const char *filename, uint64_t total_size,
                                strncpy(backing_filename, backing_file,
                                        sizeof(backing_filename));
                        } else {
-                               realpath(backing_file, backing_filename);
-                               if (stat(backing_filename, &st) != 0) {
+                               if (realpath(backing_file, backing_filename) == NULL ||
+                                   stat(backing_filename, &st) != 0) {
                                        return -1;
                                }
                        }
index 4ab88373ea8b0285a7096732c3cafccaf0ba085e..f6b720e1e0c8642612e7449d5f3e2429bb1cfc2a 100644 (file)
@@ -283,8 +283,9 @@ static uint64_t get_cluster_offset(struct tdvmdk_state *prv,
                if (!allocate)
                        return 0;
                cluster_offset = lseek(prv->fd, 0, SEEK_END);
-               ftruncate(prv->fd, cluster_offset + 
-                         (prv->cluster_sectors << 9));
+               if (ftruncate(prv->fd, cluster_offset + 
+                             (prv->cluster_sectors << 9)))
+                       return 0;
                cluster_offset >>= 9;
                /* update L2 table */
                tmp = cpu_to_le32(cluster_offset);